import os
import tornado.web
import tornado.ioloop
import tornado.httpserver
from tornado.options import define,options,parse_command_line
from app.views import LoginHandler,ChatHandler,RegisterHandler
from utils.settings import TEMPLATE_PATH,STATIC_PATH
define('port',default=8080,help='default port',type=int)


def make_app():
    return tornado.web.Application(handlers=[
        (r'/login/',LoginHandler),
        (r'/chat/',ChatHandler),
        (r'/reg/',RegisterHandler),
    ],
    autoreload=True,debug=True,template_path=TEMPLATE_PATH,static_path=STATIC_PATH,
    cookie_secret = 'qwertyuiopasdfghjkl123=',
    xsrf_cookies=True
    )


if __name__ == "__main__":
    parse_command_line()
    app = make_app()
    http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port,address='0.0.0.0')
    tornado.ioloop.IOLoop.instance().start()